<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			.red{
				color: red;
			}
			.blue{
				color: blue;
			}
			.yellow{
				color: yellow;
			}
		</style>
	</head>
	<body>
		<ul>
			<li id="java">java</li>
			<li class="blue">c++</li>
			<li id="php">php</li>
		</ul>
		<input type="button" value="给java添加样式" id="add"/>
		<input type="button" value="给c++添加样式" id="remove"/>
		<input type="button" value="给php添加样式" id="toggle"/>
		<input type="button" value="给php添加样式" id="contain"/>
		<script>
			window.onload=function(){
				document.querySelector("#add").onclick=function(){
					document.querySelector("#java").classList.add("red")
					var css =document.querySelector("#java").classList.item("color")
					var css2 =document.querySelector("#java").classList.item(0)
					console.log(css2)
					
				}
				document.querySelector("#remove").onclick=function(){
					document.querySelector(".blue").classList.remove("blue")
				}
				/* 
				 toggle:切换当前样式
				 */
				document.querySelector("#toggle").onclick=function(){
					document.querySelector("#php").classList.toggle("yellow")
				}
				/*
				 contain:查询是样式中式包含当前样式
				 */
				document.querySelector("#contain").onclick=function(){
					var boln =document.querySelector("#java").classList.contains("red")
					console.log(boln)
				}
			}
			
		</script>
	</body>
</html>